var express = require('express');
var config = require('./config/index');

var port = process.env.PORT || config.build.port;

var app = express();

var router = express.Router();

router.get('/', function (req, res, next) {
    req.url = '/index.html';
    next();
});

app.use(router);


var homeData = require('./mock/home.json');

var homeRoutes = express.Router();

homeRoutes.get('/home', function (req, res) {
    res.json({
        errno: 0,
        data: homeData
    });
});

app.use('/api', homeRoutes);

app.use(express.static('./dist'));

module.exports = app.listen(port, function (err) {
    if (err) {
        console.log(err);
        return
    }
    console.log('Listening at http://localhost:' + port + '\n')
});